/**
 * @(#) AppmssProxy.as
 *
 * @date		2011. 03. 25
 * @version		1.0
 * @author		baek kwang hyoun
 * @description	평가결과 Proxy - Proxy
 */
package com.skt.common_hr.empcontnos.model
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.common.utilSilver.textSilver;
	import com.skt.common_hr.empcontnos.model.vo.mainListVO;
	import com.wcl.dataloader.*;
	import com.wcl.utils.DateUtil;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.formatters.DateFormatter;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class EmpcontProxy extends CommonProxy
	{
		public static const NAME:String = "EmpcontProxy";

		public var mainList:ArrayCollection;
		public var mainListTop:ArrayCollection;
		public var mainListBottom:ArrayCollection;
		public var mainListHomeWork:ArrayCollection; 


		public var acYearList:ArrayCollection;
		/**
		 * 생성자
		 *
		 * @param
		 * @return void
		 */
		public function EmpcontProxy(data:Object=null)
		{
			super(NAME, data);
		}

		
		public function loadYearList(setFunc:Function):void
		{
			var obj:Object = {};
			obj.I_PERNR = Variables.myPernr;
			loadData("Z_HR_EC01", obj, loadYearListResult, listYearFault, setFunc);
		}
		
		public function loadYearListResult(event:ResultEvent):void
		{
			if(retCode==0) {
				acYearList = event.result.T_YEAR as ArrayCollection 								
				event.result.func(acYearList);
			}
		}
		
		public function loadList(year:String, setFunc:Function):void
		{
			var obj:Object = {};
			obj.I_PERNR = Variables.myPernr;
			obj.I_YEAR = year;
			loadData("Z_HR_EC01", obj, loadListResult, listFault, setFunc);
		}
		
		public function loadListResult(event:ResultEvent):void
		{
			if(retCode==0) {							
				if(event.result.OTAB2 is ArrayCollection) {
					trace('OTAB2  ok');
				}else{
					trace('OTAB2  false');
//					Alert.show("OTAB2 : " + event.result.OTAB2.length);
					event.result.OTAB2 = new ArrayCollection(event.result.OTAB2);										
				}
								
				if(event.result.OTAB is ArrayCollection) {
					trace('OTAB  ok');
				}else{
					trace('OTAB  false');
//					Alert.show("OTAB : " + event.result.OTAB.length);
					event.result.OTAB = new ArrayCollection(event.result.OTAB);
					
				}
				
				if(event.result.OTAB3 is ArrayCollection) {
					trace('OTAB3  ok');
				}else{
					trace('OTAB3  false');
//					Alert.show("OTAB : " + event.result.OTAB.length);
					event.result.OTAB3 = new ArrayCollection(event.result.OTAB3);
					
				}
				
				//acYearList = event.result.T_YEAR as ArrayCollection 								
				mainList = parseMainList(event.result.OTAB);
				mainListTop = parseTopList(event.result.OTAB2);
				mainListBottom = parseBottomList(event.result.OTAB3);
				
				var rtnObj:Object =  {};
				rtnObj.mainList = mainList;
				rtnObj.mainListTop = mainListTop;
				rtnObj.mainListBottom = mainListBottom;
				event.result.func(rtnObj);
			}
		}
		
		private function listYearFault(event:FaultEvent):void
		{
			Alert.show('HthIcProxy.as listFault err: ' + retText);
		}
		
		private function listFault(event:FaultEvent):void
		{
			Alert.show('HthIcProxy.as listFault err: ' + retText);
		}
		
		private function saveFault(event:FaultEvent):void 
		{
			Alert.show('HthIcProxy.as listFault err: ' + retText);
		}
		
					
		private static var dateFormatter:DateFormatter = new DateFormatter();
		public static function toKorString(src:Date):String
		{
			dateFormatter.formatString = "YYYY년 MM월 DD일";
			return dateFormatter.format(src); 
		}
			
		private function parseMainList(recArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();

			for each(var rec:Object in recArr) 
			{
				var vo:mainListVO = new mainListVO();
				
				
				vo.BANDT			= rec["BANDT"]; // 20140424
				
				vo.ADDR			= rec["ADDR"];
				vo.BEGDA		= rec["BEGDA"];	
				vo.CDATE		= rec["CDATE"];
				vo.CYES			= rec["CYES"];
				vo.ECODE		= rec["ECODE"];
				vo.ENAME		= rec["ENAME"];
				vo.ENDDA		= rec["ENDDA"];
				vo.ETEXT		= rec["ETEXT"];
				vo.PERNR		= textSilver.pernrFunc(rec["PERNR"]);
				vo.PYES			= rec["PYES"];
				vo.REGNO		= textSilver.regnoFunc(rec["REGNO"]);
				vo.SEQNR		= rec["SEQNR"];
				vo.ORGTX        = rec["ORGTX"];
				vo.CDATE_F 		= toKorString(DateUtil.stringToDateTime(rec["CDATE"]) );
				vo.CDATE 		= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["CDATE"]) );
				vo.PDATE		= rec["PDATE"];
				vo.CTIME		= rec["CTIME"];
				vo.JOINT		= textSilver.toDotSpaceString(DateUtil.stringToDateTime(rec["JOINT"]));
				vo.JGBN			= rec["JGBN"];	
				vo.JGBNT		= rec["JGBNT"];
				vo.JWTXT		= rec["JWTXT"];
				vo.PERIOD		= rec["PERIOD"];
				
				vo.CTIME		= DateUtil.toTimeString(DateUtil.stringToDateTime(rec["CTIME"]));
				vo.CDATE_F 		= toKorString(DateUtil.stringToDateTime(rec["CDATE"]) );
				vo.CDATE 		= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["CDATE"]) );
										
				if(vo.CDATE == '' ) {
					vo.CDATE = '';	
				} else {
					vo.CDATE 	= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["CDATE"]) ) + ' ' + vo.CTIME;	
				}
				
				
				if(vo.CYES == "X") {
					vo.JOINT = toKorString(DateUtil.stringToDateTime(rec["JOINT"]));
				}
				else {
					vo.JOINT = ""; 
				}
					
				
				vo.PDATE  		= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["PDATE"]) );
										
				if(vo.CYES == "X") {
					vo.CYES_F = "V";
				}
				else {
					vo.CYES_F = "";
				}
				
				if(vo.PYES == "X") {
					vo.PYES_F = "V";
				}
				else {
					vo.PYES_F = "";
				}
				
				retArr.addItem(vo);
			}
			return retArr;
		}
		
		public static function k(src:Date):String
		{
			dateFormatter.formatString = "YYYY년 MM월 DD일";
			return dateFormatter.format(src);
		}
		
		private function parseTopList(recArr:ArrayCollection):ArrayCollection
		{
			
			var retArr:ArrayCollection = new ArrayCollection();

			for each(var rec:Object in recArr) 
			{
				var vo:mainListVO = new mainListVO();
				vo.ADDR			= rec["ADDR"];
				vo.BEGDA		= rec["BEGDA"];	
				vo.CDATE		= rec["CDATE"];
				vo.CYES			= rec["CYES"];
				vo.ECODE		= rec["ECODE"];
				vo.ENAME		= rec["ENAME"];
				vo.ENDDA		= rec["ENDDA"];
				vo.ETEXT		= rec["ETEXT"];
				vo.PERNR		= textSilver.pernrFunc(rec["PERNR"]);
				vo.PYES			= rec["PYES"];
				vo.REGNO		= textSilver.regnoFunc(rec["REGNO"]);
				vo.SEQNR		= rec["SEQNR"];
				vo.PERIOD		= rec["PERIOD"];
				vo.PERSK		= rec["PERSK"];
				vo.PKTXT		= rec["PKTXT"];
				vo.ORGTX		= rec["ORGTX"];	
				vo.MPHONE		= rec["MPHONE"];
				vo.JOB			= rec["JOB"];
				vo.PDATE		= rec["PDATE"];
				vo.CTIME		= rec["CTIME"];
				vo.JOINT		= textSilver.toDotSpaceString(DateUtil.stringToDateTime(rec["JOINT"]));
				vo.CTIME		= rec["CTIME"];
				vo.JGBN			= rec["JGBN"];	
				vo.JGBNT		= rec["JGBNT"];
				vo.CAMT			= rec["CAMT"];
				vo.BAMT			= rec["BAMT"];
				vo.ALAMT		= rec["ALAMT"];	
				vo.BONUS		= rec["BONUS"];
				vo.OTAMT		= rec["OTAMT"];
				vo.PLAMT		= rec["PLAMT"];
				vo.WTIME		= rec["WTIME"];	
				vo.CBEGDA		= rec["CBEGDA"];
				vo.CENDDA		= rec["CENDDA"];
					
				
				vo.PDATE  		= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["PDATE"]) );
				vo.BEGDA_F		= toKorString(DateUtil.stringToDateTime(rec["CBEGDA"]) );
				vo.ENDDA_F		= toKorString(DateUtil.stringToDateTime(rec["CENDDA"]) );
				vo.CDATE_F 		= toKorString(DateUtil.stringToDateTime(rec["CDATE"]) );
				vo.CDATE 		= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["CDATE"]) );
				
//				vo.ENDDA		= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["ENDDA"]) );
//				vo.BEGDA		= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["BEGDA"]) );
				
				if(vo.CYES == 'X' ) {
					vo.CDATE 	= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["CDATE"]) ) + ' ' + DateUtil.toTimeString(DateUtil.stringToDateTime(rec["CTIME"]));	
				} else {
					vo.CDATE 	= '';
				}						
				
				if(vo.CYES == "X") {
					vo.JOINT = toKorString(DateUtil.stringToDateTime(rec["JOINT"]) );
				}
				else {
					vo.JOINT = ""; 
				}
										
				if(vo.CYES == "X") {
					vo.CYES_F = "V";
				}
				else {
					vo.CYES_F = "";
				}
				
				retArr.addItem(vo);
			}
			return retArr;
		}
		
		private function parseBottomList(recArr:ArrayCollection):ArrayCollection
		{
			
			var retArr:ArrayCollection = new ArrayCollection();

			for each(var rec:Object in recArr) 
			{
				var vo:mainListVO = new mainListVO();
				vo.SEQNR		= rec["SEQNR"];
				vo.PERIOD		= rec["PERIOD"];
				vo.PERNR		= textSilver.pernrFunc(rec["PERNR"]);
				vo.ENAME		= rec["ENAME"];	
				vo.ORGTX		= rec["ORGTX"];
				vo.ENDTT		= rec["ENDTT"];
				vo.MBPAY		= rec["MBPAY"];
				vo.YBPAY		= rec["YBPAY"];
				vo.MBONUS		= rec["MBONUS"];
				vo.YBONUS		= rec["YBONUS"];
				vo.BOPER		= rec["BOPER"];
				vo.MOTAMT		= rec["MOTAMT"];
				vo.YOTAMT		= rec["YOTAMT"];
				vo.WTIME		= rec["WTIME"];
				vo.MAJAMT		= rec["MAJAMT"];
				vo.YAJAMT		= rec["YAJAMT"];
				vo.MPLAMT		= rec["MPLAMT"];
				vo.YPLAMT		= rec["YPLAMT"];	
				vo.MBAMT		= rec["MBAMT"];
				vo.YBAMT		= rec["YBAMT"];
				vo.MLUAMT		= rec["MLUAMT"];
				vo.YLUAMT		= rec["YLUAMT"];
				vo.MTOTAL		= rec["MTOTAL"];
				vo.YTOTAL		= rec["YTOTAL"];
				vo.JOINT		= textSilver.toDotSpaceString(DateUtil.stringToDateTime(rec["JOINT"]));	
				vo.CYES			= rec["CYES"];
				vo.CDATE		= rec["CDATE"];
				vo.CTIME		= rec["CTIME"];
				vo.ECODE		= rec["ECODE"];
				vo.BEGDA		= rec["BEGDA"];
				vo.ENDDA		= rec["ENDDA"];
				vo.ENTDD		= toKorString(DateUtil.stringToDateTime(rec["ENTDD"]));
				
				vo.PDATE  		= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["PDATE"]) );
				vo.BEGDA_F		= toKorString(DateUtil.stringToDateTime(rec["CBEGDA"]) );
				vo.ENDDA_F		= toKorString(DateUtil.stringToDateTime(rec["CENDDA"]) );
				vo.CDATE_F 		= toKorString(DateUtil.stringToDateTime(rec["CDATE"]) );
				vo.CDATE 		= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["CDATE"]) );
				
				if(vo.CYES == 'X' ) {
					vo.CDATE 	= DateUtil.toDefaultString(DateUtil.stringToDateTime(rec["CDATE"]) ) + ' ' + DateUtil.toTimeString(DateUtil.stringToDateTime(rec["CTIME"]));	
				} else {
					vo.CDATE 	= '';
				}						
				
				if(vo.CYES == "X") {
					vo.JOINT = toKorString(DateUtil.stringToDateTime(rec["JOINT"]) );
				}
				else {
					vo.JOINT = ""; 
				}
										
				if(vo.CYES == "X") {
					vo.CYES_F = "V";
				}
				else {
					vo.CYES_F = "";
				}
				
				retArr.addItem(vo);
			}
			return retArr;
		}
		
	}		
}